import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

//静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login_dashboard" */'@/views/login/index'),
    hidden: true,
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */'@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName: "login_dashboard" */'@/views/dashboard/index'),
      meta: { title: '仪表台', icon: 'dashboard' }
    }]
  },
  {
    path: '/long_list',
    component: Layout,
    children: [{
      path: '',
      name: 'long_list',
      component: () => import(/* webpackChunkName: "long_list" */'@/views/long_list/index'),
      meta: { title: '长列表优化', icon: 'form' }
    }]
  }

]

const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router--(重置路由)
}

export default router
